<?php
/**
 * User: b179a9
 * Date: 05.09.11
 * Time: 17:17
 */

namespace Managers;

class Statics extends BaseManager
{
    const TABLE = '\Catalog\Statics';
    protected $__table = self::TABLE;


    public function getPage($id)
    {
        return $this->_em->createQueryBuilder()
                ->select("s")
                ->from($this->__table, "s")
                ->where("s.id= :id")
                ->setParameter("id", $id)
                ->getQuery()
                ->getArrayResult();
    }

    public function getAllPages()
    {

        return $this->_em->createQueryBuilder()
                ->select("s")
                ->from($this->__table, "s")
                ->getQuery()
                ->getArrayResult();

    }

    public function save(array $values)
    {
        $object = empty($values['id']) ? new \Catalog\Statics() : $this->_em->find(self::TABLE, $values['id']);

        if (!$object) {
            throw new \Exception('Page does not exist');
        }

        $object->setContent($values['content']);
        $object->setMenuPageName($values['menuPageName']);

        $this->_em->persist($object);
        $this->_em->flush();
        return $object;
    }



}




